/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.web.servlet;/**
 * Created by asus-pc on 2017/11/15 0015.
 */

import cn.itlaobing.dao.UserDao;
import cn.itlaobing.entity.Users;
import cn.itlaobing.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * ClassName: UserServlet <br/>
 * Function: TODO 功能描述 <br/>
 * date: 2017/11/15 0015 16:41 <br/>
 *
 * @author 卖姑娘的小柴火
 * @since JDK 1.8
 */
@WebServlet("/Servlet/*")
public class UserServlet extends BaseServlet {
    @RequestMapping("/login")
    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException {
        req.setCharacterEncoding("utf-8");
        String username=req.getParameter("username");
        String userpwd=req.getParameter("password");
        UserDao userDao=new UserDao();
        Users users=null;
        try {
            users=userDao.login(username,userpwd);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (users==null){
            req.setAttribute("msg","帐号或密码错误!!!!!!");
            toView(req,resp,"/members/login");
        }else {
//            成功
            req.getSession().setAttribute("users",users);
            toView(req,resp,"/index");
        }

    }


}
